namespace Ds.DataBase.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class _20200713001 : DbMigration
    {
        public override void Up()
        {
            DropForeignKey("dbo.ZhiWeis", "MoBan_Main_mbid", "dbo.MoBan_Main");
            DropForeignKey("dbo.MoBan_Main", "KeShiZhiWu_id", "dbo.KeShiZhiWus");
            DropIndex("dbo.ZhiWeis", new[] { "MoBan_Main_mbid" });
            DropIndex("dbo.MoBan_Main", new[] { "KeShiZhiWu_id" });
            CreateTable(
                "dbo.MoBan_MainKeShiZhiWu",
                c => new
                    {
                        MoBan_Main_mbid = c.Int(nullable: false),
                        KeShiZhiWu_id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.MoBan_Main_mbid, t.KeShiZhiWu_id })
                .ForeignKey("dbo.MoBan_Main", t => t.MoBan_Main_mbid, cascadeDelete: true)
                .ForeignKey("dbo.KeShiZhiWus", t => t.KeShiZhiWu_id, cascadeDelete: true)
                .Index(t => t.MoBan_Main_mbid)
                .Index(t => t.KeShiZhiWu_id);
            
            DropColumn("dbo.ZhiWeis", "MoBan_Main_mbid");
            DropColumn("dbo.MoBan_Main", "KeShiZhiWu_id");
        }
        
        public override void Down()
        {
            AddColumn("dbo.MoBan_Main", "KeShiZhiWu_id", c => c.Int());
            AddColumn("dbo.ZhiWeis", "MoBan_Main_mbid", c => c.Int());
            DropForeignKey("dbo.MoBan_MainKeShiZhiWu", "KeShiZhiWu_id", "dbo.KeShiZhiWus");
            DropForeignKey("dbo.MoBan_MainKeShiZhiWu", "MoBan_Main_mbid", "dbo.MoBan_Main");
            DropIndex("dbo.MoBan_MainKeShiZhiWu", new[] { "KeShiZhiWu_id" });
            DropIndex("dbo.MoBan_MainKeShiZhiWu", new[] { "MoBan_Main_mbid" });
            DropTable("dbo.MoBan_MainKeShiZhiWu");
            CreateIndex("dbo.MoBan_Main", "KeShiZhiWu_id");
            CreateIndex("dbo.ZhiWeis", "MoBan_Main_mbid");
            AddForeignKey("dbo.MoBan_Main", "KeShiZhiWu_id", "dbo.KeShiZhiWus", "id");
            AddForeignKey("dbo.ZhiWeis", "MoBan_Main_mbid", "dbo.MoBan_Main", "mbid");
        }
    }
}
